package cn.edu.scau.cmi.chenjia.clientFxml;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.chenjia.abstractFactory.*;
import cn.edu.scau.cmi.chenjia.simpleFactoryMethod.*;
import cn.edu.scau.cmi.chenjia.factory.*;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import javafx.scene.control.TextArea;

import javafx.scene.control.ComboBox;

public class AllFactoryUIController implements Initializable {
	@FXML
	private TextArea t1;
	@FXML
	private ComboBox cb1;
	@FXML
	private ComboBox cb2;
	@FXML
	private Button bt;

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO Auto-generated method stub
		cb1.setValue("简单工厂方法");
		cb2.setValue("牛肉");
		cb1.setItems(FXCollections.observableArrayList("简单工厂方法", "工厂模式", "抽象工厂模式"));
		cb2.setItems(FXCollections.observableArrayList("牛肉", "鸡肉", "猪肉"));
	}

	public void setItems() {
		switch ((String) cb1.getValue()) {
		case "简单工厂方法":
			cb2.setValue("牛肉");
			cb2.setItems(FXCollections.observableArrayList("牛肉", "鸡肉", "猪肉"));
			break;
		case "工厂模式":
			cb2.setValue("牛肉");
			cb2.setItems(FXCollections.observableArrayList("牛肉", "鸡肉", "猪肉"));
			break;
		case "抽象工厂模式":
			cb2.setValue("Wens牛肉");
			cb2.setItems(FXCollections.observableArrayList("Wens牛肉", "Wens鸡肉", "Wens猪肉", "Tianbang牛肉", "Tianbang鸡肉",
					"Tianbang猪肉", "Aonong牛肉", "Aonong鸡肉", "Aonong猪肉"));
			break;
		default:
			break;
		}
	}

	public void button() {
		String a = (String) cb1.getValue();
		if (a == "简单工厂方法") {
			String b = (String) cb2.getValue();
			if (b == "牛肉") {
				String str = cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Beef.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "鸡肉") {
				String str = cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Chicken.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "猪肉") {
				String str = cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Pork.eat();
				t1.appendText(str + '\n');
			}
		} 
		else if (a == "工厂模式") {
			String b = (String) cb2.getValue();
			if (b == "牛肉") {
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Meat meat = cn.edu.scau.cmi.chenjia.factory.BeefMeatFactory
						.eat();
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Beef beef = (cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Beef) meat;
				String str = beef.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "鸡肉") {
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Meat meat = cn.edu.scau.cmi.chenjia.factory.ChickenMeatFactory
						.eat();
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Chicken chicken = (cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Chicken) meat;
				String str = chicken.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "猪肉") {
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Meat meat = cn.edu.scau.cmi.chenjia.factory.PorkMeatFactory
						.eat();
				cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Pork pork = (cn.edu.scau.cmi.chenjia.simpleFactoryMethod.Pork) meat;
				String str = pork.eat();
				t1.appendText(str + '\n');
			}
		} 
		else if (a == "抽象工厂模式") {
			String b = (String) cb2.getValue();
			if (b == "Wens牛肉") {
				WensFactory aonong = new WensFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.WensBeef beef = (cn.edu.scau.cmi.chenjia.abstractFactory.WensBeef) aonong
						.createBeef();
				String str = beef.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "Wens鸡肉") {
				WensFactory aonong = new WensFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.WensChicken chicken = (cn.edu.scau.cmi.chenjia.abstractFactory.WensChicken) aonong
						.createChicken();
				String str = chicken.eat();
				t1.appendText(str + '\n');
			}
			else if (b == "Wens猪肉") {
				WensFactory aonong = new WensFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.WensPork pork = (cn.edu.scau.cmi.chenjia.abstractFactory.WensPork) aonong
						.createPork();
				String str = pork.eat();
				t1.appendText(str + '\n');
			}
			else if (b == "Tianbang牛肉") {
				TianbangFactory aonong = new TianbangFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.TianbangBeef beef = (cn.edu.scau.cmi.chenjia.abstractFactory.TianbangBeef) aonong
						.createBeef();
				String str = beef.eat();
				t1.appendText(str + '\n');
			}
			else if (b == "Tianbang鸡肉") {
				TianbangFactory aonong = new TianbangFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.TianbangChicken chicken = (cn.edu.scau.cmi.chenjia.abstractFactory.TianbangChicken) aonong
						.createChicken();
				String str = chicken.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "Tianbang猪肉") {
				TianbangFactory aonong = new TianbangFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.TianbangPork pork = (cn.edu.scau.cmi.chenjia.abstractFactory.TianbangPork) aonong
						.createPork();
				String str = pork.eat();
				t1.appendText(str + '\n');
			}
			else if (b == "Aonong牛肉") {
				AonongFactory aonong = new AonongFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.AonongBeef beef = (cn.edu.scau.cmi.chenjia.abstractFactory.AonongBeef) aonong
						.createBeef();
				String str = beef.eat();
				t1.appendText(str + '\n');
			}
			else if (b == "Aonong鸡肉") {
				AonongFactory aonong = new AonongFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.AonongChicken chicken = (cn.edu.scau.cmi.chenjia.abstractFactory.AonongChicken) aonong
						.createChicken();
				String str = chicken.eat();
				t1.appendText(str + '\n');
			} 
			else if (b == "Aonong猪肉") {
				AonongFactory aonong = new AonongFactory();
				cn.edu.scau.cmi.chenjia.abstractFactory.AonongPork pork = (cn.edu.scau.cmi.chenjia.abstractFactory.AonongPork) aonong
						.createPork();
				String str = pork.eat();
				t1.appendText(str + '\n');
			}
		}
	}
}
